<template>
  <Window
    :width="490"
    :minWidth="490"
    :height="306"
    :right="100"
    :floatright="true"
    :title="lang.title"
    @cancel="cancel"
    @ok="ok"
    :footervisible="true"
    @showclick="showSelect = false"
  >
    <div class="xbsj-flatten">
      <!-- 名称 -->
      <div class="flatten">
        <label>{{ lang.name }}</label>
        <input style="float: left" type="text" v-model="model.name" />
      </div>
      <div class="flatten-flex">
        <!-- 鼠标点选 -->
        <div class="flatten">
          <label>{{ lang.weizhi }}</label>
          <div class="buttonGroup">
            <button
              class="attitudeEditCameraButton"
              @click="model.creating = !model.creating"
              :class="model.creating ? 'btncoloron' : ''"
            >
              {{ lang.creating }}
            </button>
            <button
              style="margin-left: 20px"
              class="attitudeEditCameraButton"
              @click="model.editing = !model.editing"
              :class="model.editing ? 'btncoloron' : ''"
            >
              {{ lang.editing }}
            </button>
            <button
              style="margin-left: 20px"
              class="attitudeEditCameraButton"
              @click="flyto"
            >
              {{ lang.flyto }}
            </button>
          </div>
        </div>
      </div>

      <div class="flatten">
        <!-- 高度 -->
        <label>{{ lang.height }}</label>
        <div class="flatten-box">
          <XbsjInputNumber
            style="float: left; width: calc(33.3% - 86px)"
            v-model.number="model.height"
          ></XbsjInputNumber>
        </div>
        <!-- 厚度 -->
        <label>{{ lang.depth }}</label>
        <div class="flatten-box">
          <XbsjInputNumber
            style="float: left; width: calc(33.3% - 86px)"
            v-model.number="model.depth"
          ></XbsjInputNumber>
        </div>
        <!-- 缩放比例 -->
        <label>{{ lang.scale }}</label>
        <div class="flatten-box">
          <XbsjInputNumber
            style="float: left; width: calc(33.3% - 84px)"
            v-model.number="model.scale"
          ></XbsjInputNumber>
        </div>
      </div>

      <div class="flatten">
        <!-- 纹理图像 -->
        <label>{{ lang.imgurl }}</label>
        <div class="flatten-box">
          <input
            style="float: left; width: calc(50% - 90px)"
            v-model="model.imageUrl"
          />
        </div>
        <!-- 纹理高度 -->
        <label>{{ lang.wallimageheight }}</label>
        <div class="flatten-box">
          <XbsjInputNumber
            style="float: left; width: calc(50% - 90px)"
            v-model.number="model.wallImageHeight"
          ></XbsjInputNumber>
        </div>
      </div>

      <div class="flatten">
        <!-- 墙顶纹理图像 -->
        <label>{{ lang.roofimgurl }}</label>
        <div class="flatten-box">
          <input
            style="float: left; width: calc(50% - 90px)"
            v-model="model.roofImageUrl"
          />
        </div>
        <!-- 墙顶纹理高度 -->
        <label>{{ lang.roofimageheight }}</label>
        <div class="flatten-box">
          <XbsjInputNumber
            style="float: left; width: calc(50% - 90px)"
            v-model.number="model.roofImageHeight"
          ></XbsjInputNumber>
        </div>
      </div>
    </div>
  </Window>
</template>

<script>
/* eslint-disable */
import languagejs from "./index_locale";
import XbsjInputNumber from "../Slider/input-number";
import Window from "../Window/Index";

export default {
  components: {
    XbsjInputNumber,
    Window
  },
  props: {
    getBind: Function
  },
  data() {
    return {
      lang: languagejs.zh,
      showPinSelect: false,
      makiIconObj: {},
      drag_over: false,
      model: {
        name: "",
        show: true,
        creating: true,
        editing: false,
        enabled: true,
        height: 3.0,
        depth: 0.8,
        scale: 1.0,
        imageUrl: "",
        wallImageHeight: 3.0,
        roofImageUrl: "",
        roofImageHeight: 3.0
      },
      pinstyletype: true,
      langs: languagejs
    };
  },
  created() {},
  mounted() {
    // 数据关联
    this._disposers = this._disposers || [];
    var czmObj = this.getBind();
    // console.log(czmObj);

    if (czmObj) {
      this._czmObj = czmObj;
      const bindData = {
        name: "model.name",
        creating: "model.creating",
        show: "model.show",
        editing: "model.editing",
        height: "model.height",
        depth: "model.depth",
        scale: "model.scale",
        imageUrl: "model.imageUrl",
        wallImageHeight: "model.wallImageHeight",
        roofImageUrl: "model.roofImageUrl",
        roofImageHeight: "model.roofImageHeight",
        enabled: "model.enabled"
      };

      Object.entries(bindData).forEach(([sm, vm]) => {
        if (typeof vm === "string") {
          this._disposers.push(XE.MVVM.bind(this, vm, czmObj, sm));
        } else {
          this._disposers.push(vm.handler(this, vm.prop, czmObj, sm));
        }
      });
    }
  },
  computed: {
    name() {
      return this.model.name;
    },
    guid() {
      return this.getBind().guid;
    }
  },
  methods: {
    close() {
      this.$parent.destroyTool(this);
    },
    cancel() {
      this.close();
      const modelToolObj = this._czmObj;
      if (!modelToolObj) {
        return;
      }
      modelToolObj.positionEditing = false;
      if (modelToolObj.isCreating) {
        modelToolObj.isCreating = false;
        modelToolObj.destroy();
      }
    },
    ok() {
      this.close();
      const modelToolObj = this._czmObj;
      modelToolObj.editing = false;
      if (!modelToolObj) {
        return;
      }
      modelToolObj.positionEditing = false;
      if (modelToolObj.isCreating) {
        modelToolObj.isCreating = false;
        const sceneObject = new XE.SceneTree.Leaf(modelToolObj);
        this.$parent.addSceneObject(sceneObject);
      }
    },

    flyto() {
      this._czmObj.flyTo();
    },
    //拖拽移动上面
    dragOver(e) {
      e.preventDefault();
      let czmObj = this.$parent.getCzmObjectFromDrag(e.dataTransfer);
      if (czmObj && czmObj.positions !== undefined) {
        e.dataTransfer.dropEffect = "copy";
        this.drag_over = true;
      } else {
        e.dataTransfer.dropEffect = "none";
      }
    },
    dragLeave() {
      this.drag_over = false;
    },
    //拖拽放置
    drop(e) {
      this.drag_over = false;
      e.preventDefault();
      let czmObj = this.$parent.getCzmObjectFromDrag(e.dataTransfer);
      if (czmObj && czmObj.positions !== undefined) {
        this._czmObj.creating = false;
        this.$parent.getCzmObjectPositionFromDrag(czmObj, this._czmObj);
      }
    }
  },
  beforeDestroy() {
    // 解绑数据关联
    this._polygonDisposers = this._polygonDisposers && this._polygonDisposers();
    this._disposers.forEach(e => e());
    this._disposers.length = 0;
  }
};
</script>

<style scoped>
.flatten-flex {
  display: flex;
}
.field {
  padding-left: 4px;
  display: inline-block;
  width: 220px;
}

.item-btn-box input {
  float: left;
}

.flatten-btn {
  background: none;
  border: none;
  width: 100%;
  height: 34px;
  /* border-left: 1px solid black; */
  margin-top: -1px;
  cursor: pointer;
}
.flatten-btn:focus {
  outline: none;
}
.item-btn-box {
  width: 100%;
  padding-top: 1px;
  border: 1px solid #000;
  border-collapse: collapse;
}
.item-btn-box thead tr {
  border-bottom: 1px solid #000;
}

.item-btn-box thead tr th {
  width: 16.66%;
  text-align: center;
  border-right: 1px solid #000;
}
.item-btn-box tbody tr td {
  border-right: 1px solid #000;
  text-align: center;
}
.item-btn-box tbody tr {
  border-top: 1px solid #000;
}

.iteminput {
  width: 72px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  border: none;
  color: #dddddd;
  padding-left: 10px;
  margin: 2px;
}
.item-order {
  width: 51px;
  height: 34px;
  text-align: center;
  line-height: 30px;
  border-right: none !important;
  border-top: none !important;
}
button {
  background: none;
  border: none;
  margin: 0 auto;
  display: block;
  line-height: 25px;
}
.header-add {
  width: 61px;
  height: 30px;
  /* border-bottom: none !important; */
}
.falatten-body-item div {
  float: left;
}
.header-content {
  width: 264px;
  height: 30px;
  border-left: none !important;
  border-right: none !important;
}
.flatten-table-header {
  width: 100%;
  height: 30px;
}
.flatten-table-header .border {
  float: left;
}
.flatten-table-order {
  width: 51px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  /* border-bottom: none !important; */
}
.xbsj-flatten {
  min-width: 462px;
}
.xbsj-flatten > div {
  width: 100%;
  height: 28px;
  margin-top: 10px;
}
.xbsj-flatten label {
  float: left;
  min-width: 60px;
  height: 28px;
  line-height: 28px;
  text-align: right;
  margin-left: 8px;
  margin-right: 15px;
}
.xbsj-flatten .flatten input,
.xbsj-flatten .attributePath input {
  width: calc(100% - 100px);
  height: 28px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  border: none;
  color: #dddddd;
  padding-left: 10px;
}
.xbsj-flatten .attributePlay button {
  width: 99px;
  height: 28px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  border: none;
  cursor: pointer;
}

.xbsj-flatten .attributeLocation input,
.xbsj-flatten .attributeAttitude input {
  width: 66px;
  height: 28px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  border: none;
  color: #dddddd;
  padding-left: 10px;
  margin-right: 6px;
}
input[type="text"]:focus,
button:focus {
  outline: 1px solid rgba(31, 255, 255, 1);
}
.flatten-table {
  display: inline-block;
  width: 80%;
}
.border {
  border: 1px solid black;
}
.select-ul {
  width: 80%;
  padding-left: 8px;
  margin-left: calc(10% + 23px);
  background: rgba(138, 138, 138, 1);
  z-index: 9999;
  position: relative;
}

.cutselectbox {
  width: calc(100% - 102px);
  background: rgba(138, 138, 138, 1);
  position: absolute;
  left: 78px;
  border-radius: 0px 0px 4px 4px;
  overflow: auto;
  z-index: 999;
}
.cutselectbox div {
  width: 100%;
  height: 28px;
  font-size: 14px;
  color: rgba(221, 221, 221, 1);
  cursor: pointer;
  line-height: 28px;
}

.cutselectbox div:hover {
  background: rgba(107, 107, 107, 1);
}

.cutselectbox span {
  display: inline-block;
  /* width: 72px; */
  text-align: left;
  margin-left: 10px;
}

.buttonGroup {
  display: inline-block;
}
.buttonGroup div {
  display: inline-block;
  height: 25px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  color: #dddddd;
}
.attitudeEditCameraButton {
  color: #dddddd;
}
.btncoloron {
  color: #1fffff !important;
}
button {
  background: none;
  border: none;
  margin: 0 auto;
  display: block;
  line-height: 25px;
  outline: none;
}
button:focus {
  outline: none !important;
}
.attitudeEditCameraButton {
  display: block;
  float: left;
  height: 25px;
  margin-left: 0;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  color: #dddddd;
}
.xbsj-videoAttribute .attributePlay button {
  width: 99px;
  height: 28px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  border: none;
  cursor: pointer;
}
</style>